<?php
namespace app\index\model;

use think\Model;

class EngineeringModel extends Model
{
    protected $table = 'sf_engineering';
    protected $autoWriteTimestamp = true;
    protected $createTime = 'add_time';
    protected $updateTime = 'update_time';
    public function __construct($data = [],$event = [])
    {
        foreach ($event as $key=>$value){
            EngineeringModel::event($key,$value);
        }
        parent::__construct($data);
    }
    public function imgs()
    {
        return $this->hasMany('EngineeringImgModel','message_id','id');
    }
    public function engineeringType()
    {
        return $this->hasOne('EngineeringTypeModel','id','engineering_type');
    }
    public function getEngineeringTypeAttr($data){
        if($data == 1){
            return '隔音材料';
        }elseif($data == 2){
            return '声学安装';
        }else{
            return '声学设计';
        }
    }
    public function getAddTimeAttr($data){
        return date('Y-m-d H:i:s',$data);
    }
    public function getUpdateTimeAttr($data){
        return date('Y-m-d H:i:s',$data);
    }
    public function getUidAttr($data){
        $user = UserModel::get(['id'=>$data]);
        return $str = substr_replace($user['mobile'], '****', 3, 4);
    }
}
